package com.sun.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.exception.SystemException;
import com.sun.mapper.EmployeesMapper;
import com.sun.pojo.dto.EmployeesRegisterDTO;
import com.sun.pojo.entity.Employees;
import com.sun.pojo.vo.R;
import com.sun.service.EmployeesService;
import com.sun.utils.DingDingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author SunRui
 * @description TODO
 * @date 2024/10/21 9:58
 */
@Service
public class EmployeesServiceImpl implements EmployeesService {
    @Autowired
    EmployeesMapper employeesMapper;
    @Override
    public PageInfo<Employees> selectAllByPage(Employees employees,Integer pageNum) {
        PageHelper.startPage(pageNum,5);
        List<Employees> employeesList = employeesMapper.selectAllByPage(employees);
        PageInfo<Employees> pageInfo  = new PageInfo<>(employeesList);
        return pageInfo;
    }

    @Override
    public Employees selectByEmployeeId(Integer employeeId) {
        return employeesMapper.selectByEmployeeId(employeeId);
    }

    @Override
    public int insertSelective(Employees employees) {
        return employeesMapper.insertSelective(employees);
    }

    @Override
    public int updateByEmployeeId(Employees updated, Integer employeeId) {
        return employeesMapper.updateByEmployeeId(updated, employeeId);
    }

    @Override
    public int deleteByEmployeeId(Integer employeeId) {
        return employeesMapper.deleteByEmployeeId(employeeId);
    }

    @Override
    public R selectByLoginName(String loginName,String password) {
        Employees employees = employeesMapper.selectByLoginName(loginName);
        if (employees == null){
            throw new SystemException(5001,"用户不存在");
        }
        if (!employees.getPassword().equals(password)){
            throw new SystemException(5002,"密码错误");
        }
         return R.success(employees);
    }

    @Override
    public int registerEmployees(EmployeesRegisterDTO employeesRegisterDTO) {
        return employeesMapper.registerEmployees(employeesRegisterDTO);
    }


}
